/**
 * 
 */
package org.cuatrovientos.erp.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.cuatrovientos.erp.dao.CityDAOInterface;
import org.cuatrovientos.erp.model.City;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Pablo_Guerrero
 * This class implements CityBOInterface
 *
 */
public class CityBO implements CityBOInterface{

	// Get log4j logger
		private static final Logger logger = Logger.getLogger(CityBO.class);
		
		@Autowired
	    private CityDAOInterface cityDAO;
		
	/**
	 * @param int id
	 * @return City city
	 * This method returns a city selected by it's id
	 */
	@Override
	public City selectById(int id) {
		logger.info("selectById: " + id);
		return cityDAO.selectById(id);
	}
	
	/**
	 * @return All the cities we have in the database
	 */
	@Override
	public List<City> selectAll() {
		logger.info("selectAll: ");
		return cityDAO.selectAll();
	}
	
	/**
	 * @return The number of cities we have in the database
	 */
	@Override
	public List<City> search(String name) {
		logger.info("search : " + name);
		return cityDAO.search(name);
	}
	
	/**
	 * @param int id
	 * This method deletes the city selected by id
	 */
	@Override
	public void deleteById(int id) {
		logger.info("delete by: " + id + " id");
		cityDAO.deleteById(id);
	}
	
	/**
	 * @param City city
	 * This method insert a city in the database passed by parameter
	 */
	@Override
	public void insert(City city) {
		logger.info("insert: " + city);
		cityDAO.insert(city);
	}
	
	/**
	 * @param City city
	 * This method updates a city passed by parameter
	 */
	@Override
	public void update(City city) {
		logger.info("update: " + city);
		cityDAO.update(city);
	}
	
	/**
	 * @param City city
	 * This method deletes a city passed by parameter
	 */
	@Override
	public void delete(City city) {
		logger.info("delete: " + city);
		cityDAO.delete(city);
	}

}
